home *** CD-ROM | disk | FTP | other *** search
/ Keystone Learning XML: Introduction / Keystone Learning Introduction to XML.iso / Sample Files / Chapter 9 / Employees.asp < prev    next >
Encoding:
Text File  |  1999-12-09  |  3.4 KB  |  91 lines

  1. <%@ Language="VBScript" %>
  2. <?xml version="1.0" standalone="yes"?>
  3. <!DOCTYPE employees [
  4.     <!ELEMENT employees ( employee+ )>
  5.  
  6.     <!ELEMENT employee (name, position, address, phone)>
  7.     <!ATTLIST employee id ID #REQUIRED>
  8.  
  9.     <!ELEMENT name (first, last)>
  10.     <!ELEMENT first (#PCDATA)>
  11.     <!ELEMENT last  (#PCDATA)>
  12.  
  13.     <!ELEMENT position (#PCDATA)>
  14.  
  15.     <!ELEMENT address (street?, city?, state?, zip?)>
  16.     <!ELEMENT street (#PCDATA)>
  17.     <!ELEMENT city   (#PCDATA)>
  18.     <!ELEMENT state  (#PCDATA)>
  19.     <!ELEMENT zip    (#PCDATA)>
  20.  
  21.     <!ELEMENT phone (main, office*, fax*, mobile*, home*)>
  22.     <!ELEMENT main   (#PCDATA)>
  23.     <!ELEMENT office (#PCDATA)>
  24.     <!ELEMENT fax    (#PCDATA)>
  25.     <!ELEMENT mobile (#PCDATA)>
  26.     <!ELEMENT home   (#PCDATA)>
  27. ]>
  28.  
  29. <employees>
  30.  
  31. <%
  32.     Dim oConn       ' ADO connection object.
  33.     Dim oRs         ' Employee recordset object.
  34.     Dim oRsPhone    ' Emp phone recordset object.
  35.     Dim strSql      ' SQL string
  36.  
  37.     ' Establish a connection to the database.    
  38.     Set oConn = Server.CreateObject("ADODB.Connection")
  39.     Call oConn.Open( "DSN=Employees", "Admin", "" )
  40.      
  41.     ' Open a recordset containing all of the employees.
  42.     strSql = "SELECT * FROM employees ORDER BY lastname, firstname"
  43.     Set oRs = Server.CreateObject( "ADODB.Recordset" )
  44.     Call oRs.Open( strSql, oConn, adOpenStatic )
  45.  
  46.     ' Iterate through all of the employees in
  47.     ' the database and generate the appropriate
  48.     ' XML document that contains their information.    
  49.     While Not oRs.EOF
  50.  
  51.         ' Display all of the employee information
  52.         ' that is in the employee table.
  53.         Response.Write( "<employee id=""" & oRs("id") & """>" & vbCrLf )
  54.         Response.Write( "    <name>" & vbCrLf )
  55.         Response.Write( "        <first>" & oRs("firstname") & "</first>" & vbCrLf )
  56.         Response.Write( "        <last>" & oRs("lastname") & "</last>" & vbCrLf )
  57.         Response.Write( "    </name>" & vbCrLf )
  58.         Response.Write( "    <position>" & oRs("position") & "</position>" & vbCrLf )
  59.         Response.Write( "    <address>" & vbCrLf )
  60.         Response.Write( "        <street>" & oRs("street") & "</street>" & vbCrLf )
  61.         Response.Write( "        <city>" & oRs("city") & "</city>" & vbCrLf )
  62.         Response.Write( "        <state>" & oRs("state") & "</state>" & vbCrLf )
  63.         Response.Write( "        <zip>" & oRs("zip") & "</zip>" & vbCrLf )
  64.         Response.Write( "    </address>" & vbCrLf )
  65.         Response.Write( "    <phone>" & vbCrLf )
  66.         
  67.         ' Get the phone numbers for this employee
  68.         ' and generate the appropriate tags and content.
  69.         Set oRsPhones = Server.CreateObject( "ADODB.Recordset" )
  70.         Call oRsPhones.Open( "SELECT * FROM phonenumbers WHERE id = '" & oRs("id") & "'", oConn )
  71.     
  72.         While Not oRsPhones.EOF
  73.             ' Generate the tag containing the appropriate
  74.             ' phone information (type and number)
  75.             Response.Write( "        <" & oRsPhones("phonetype") & ">" )
  76.             Response.Write( oRsPhones("phonenumber") )
  77.             Response.Write( "</" & oRsPhones("phonetype") & ">" & vbCrLf )
  78.             oRsPhones.MoveNext
  79.         Wend
  80.         oRsPhones.Close
  81.         
  82.         Response.Write( "    </phone>" & vbCrLf )
  83.         Response.Write( "</employee>" & vbCrLf & vbCrLf )
  84.         
  85.         oRs.MoveNext 
  86.     Wend
  87.     
  88.     oRs.Close
  89.     oConn.Close 
  90. %>
  91. </employees>